package com.cx.controller;

import com.cx.common.ApiReturn;
import com.cx.pojo.Wheel;
import com.cx.service.WheelService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("wheel")
@CrossOrigin//跨域
public class WheelController {

    @Autowired
    WheelService wheelService;

    //添加车轮制动
    @RequestMapping("insertWheel")
    @ResponseBody
    public ApiReturn insertWheel(Wheel wheel){
        int rows = wheelService.insert(wheel);
        if (rows<1){
            return ApiReturn.error("添加失败");
        }
        return  ApiReturn.success("添加成功");
    }

    //修改车轮制动
    @RequestMapping("updateWheel")
    @ResponseBody
    public ApiReturn updateWheel(Wheel wheel){
        int rows = wheelService.updateByPrimaryKey(wheel);
        if (rows<1){
            return ApiReturn.error("修改失败");
        }
        return ApiReturn.success("修改成功");
    }

    //删除车轮制动
    @RequestMapping("deleteWheel")
    @ResponseBody
    public ApiReturn deleteWheel(Integer wheelId) {
        int rows = wheelService.deleteByPrimaryKey(wheelId);
        if (rows < 1) {
            return ApiReturn.error("删除失败");
        }
        return ApiReturn.success("删除成功");
    }

    //根据id查询车轮制动
    @RequestMapping("selectWheelById")
    @ResponseBody
    public ApiReturn selectWheelById(Integer wheelId) {
        Wheel wheelInfo = wheelService.selectByPrimaryKey(wheelId);
        if (wheelInfo != null) {
            return ApiReturn.success("车轮制动数据详情",wheelInfo);
        }
        return ApiReturn.error("未获取该车轮制动数据详情");
    }

    //查询所有车轮制动
    @RequestMapping("selectAllWheel")
    @ResponseBody
    public ApiReturn selectAllWheel(Wheel wheel) {
        PageInfo<Wheel> page = wheelService.selectAllWheel(wheel);
        if (page.getList() != null) {
            return ApiReturn.success("所有车轮制动数据",page);
        }
        return ApiReturn.error("无数据");
    }
}
